package lab02.test13;

public class Gymnastics extends ComputerAverage {
    @Override
    //去掉一个最低分，去掉一个最高分，然后求平均分
    double average(double[] score) {
        //赋值，避免影响原数组的值
        double[] score1 = new double[score.length];
        for (int i = 0;i < score.length;i++) {
            score1[i] = score[i];
        }

        //去掉一个最低分，去掉一个最高分
        for(int i = 0;i < score1.length-1;i++){
            for(int j = 0;j < score1.length- i - 1;j++){
                if(score1[j] > score1[j+1]){
                    double temp = score1[j];
                    score1[j] = score1[j+1];
                    score1[j+1] = temp;
                }
            }
        }
        double sum = 0;
        for (int i = 0;i < score.length - 2;i++)
        sum += score1[i+1];
        double average = sum / (score1.length - 2);
        return average;
    }
}
